<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="老人姓名" prop="elderName">
        <el-input
          v-model="queryParams.elderName"
          placeholder="请输入老人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="birthDate">
        <el-date-picker clearable
          v-model="queryParams.birthDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择出生日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别(0:男，1:女)" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别(0:男，1:女)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="健康评分" prop="healthScore">
        <el-input
          v-model="queryParams.healthScore"
          placeholder="请输入健康评分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="危险等级(健康, 提示, 风险, 危险, 严重危险)" prop="riskLevel">
        <el-input
          v-model="queryParams.riskLevel"
          placeholder="请输入危险等级(健康, 提示, 风险, 危险, 严重危险)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否建议入住(0:建议，1:不建议)" prop="suggestionForAdmission">
        <el-input
          v-model="queryParams.suggestionForAdmission"
          placeholder="请输入是否建议入住(0:建议，1:不建议)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推荐护理等级" prop="nursingLevelName">
        <el-input
          v-model="queryParams.nursingLevelName"
          placeholder="请输入推荐护理等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总检日期" prop="totalCheckDate">
        <el-input
          v-model="queryParams.totalCheckDate"
          placeholder="请输入总检日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体检机构" prop="physicalExamInstitution">
        <el-input
          v-model="queryParams.physicalExamInstitution"
          placeholder="请输入体检机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="体检报告URL链接" prop="physicalReportUrl">
        <el-input
          v-model="queryParams.physicalReportUrl"
          placeholder="请输入体检报告URL链接"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评估时间" prop="assessmentTime">
        <el-date-picker clearable
          v-model="queryParams.assessmentTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择评估时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="健康系统分值" prop="systemScore">
        <el-input
          v-model="queryParams.systemScore"
          placeholder="请输入健康系统分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['nursing:assessment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['nursing:assessment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['nursing:assessment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['nursing:assessment:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="assessmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="老人姓名" align="center" prop="elderName" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="出生日期" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="性别(0:男，1:女)" align="center" prop="gender" />
      <el-table-column label="健康评分" align="center" prop="healthScore" />
      <el-table-column label="危险等级(健康, 提示, 风险, 危险, 严重危险)" align="center" prop="riskLevel" />
      <el-table-column label="是否建议入住(0:建议，1:不建议)" align="center" prop="suggestionForAdmission" />
      <el-table-column label="推荐护理等级" align="center" prop="nursingLevelName" />
      <el-table-column label="入住情况(0:已入住，1:未入住)" align="center" prop="admissionStatus" />
      <el-table-column label="总检日期" align="center" prop="totalCheckDate" />
      <el-table-column label="体检机构" align="center" prop="physicalExamInstitution" />
      <el-table-column label="体检报告URL链接" align="center" prop="physicalReportUrl" />
      <el-table-column label="评估时间" align="center" prop="assessmentTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assessmentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报告总结" align="center" prop="reportSummary" />
      <el-table-column label="疾病风险" align="center" prop="diseaseRisk" />
      <el-table-column label="异常分析" align="center" prop="abnormalAnalysis" />
      <el-table-column label="健康系统分值" align="center" prop="systemScore" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['nursing:assessment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['nursing:assessment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改健康评估对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="老人姓名" prop="elderName">
          <el-input v-model="form.elderName" placeholder="请输入老人姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker clearable
            v-model="form.birthDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="性别(0:男，1:女)" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别(0:男，1:女)" />
        </el-form-item>
        <el-form-item label="健康评分" prop="healthScore">
          <el-input v-model="form.healthScore" placeholder="请输入健康评分" />
        </el-form-item>
        <el-form-item label="危险等级(健康, 提示, 风险, 危险, 严重危险)" prop="riskLevel">
          <el-input v-model="form.riskLevel" placeholder="请输入危险等级(健康, 提示, 风险, 危险, 严重危险)" />
        </el-form-item>
        <el-form-item label="是否建议入住(0:建议，1:不建议)" prop="suggestionForAdmission">
          <el-input v-model="form.suggestionForAdmission" placeholder="请输入是否建议入住(0:建议，1:不建议)" />
        </el-form-item>
        <el-form-item label="推荐护理等级" prop="nursingLevelName">
          <el-input v-model="form.nursingLevelName" placeholder="请输入推荐护理等级" />
        </el-form-item>
        <el-form-item label="总检日期" prop="totalCheckDate">
          <el-input v-model="form.totalCheckDate" placeholder="请输入总检日期" />
        </el-form-item>
        <el-form-item label="体检机构" prop="physicalExamInstitution">
          <el-input v-model="form.physicalExamInstitution" placeholder="请输入体检机构" />
        </el-form-item>
        <el-form-item label="体检报告URL链接" prop="physicalReportUrl">
          <el-input v-model="form.physicalReportUrl" placeholder="请输入体检报告URL链接" />
        </el-form-item>
        <el-form-item label="评估时间" prop="assessmentTime">
          <el-date-picker clearable
            v-model="form.assessmentTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择评估时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报告总结" prop="reportSummary">
          <el-input v-model="form.reportSummary" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="疾病风险" prop="diseaseRisk">
          <el-input v-model="form.diseaseRisk" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="异常分析" prop="abnormalAnalysis">
          <el-input v-model="form.abnormalAnalysis" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="健康系统分值" prop="systemScore">
          <el-input v-model="form.systemScore" placeholder="请输入健康系统分值" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAssessment, getAssessment, delAssessment, addAssessment, updateAssessment } from "@/api/nursing/assessment";

export default {
  name: "Assessment",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 健康评估表格数据
      assessmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        elderName: null,
        idCard: null,
        birthDate: null,
        age: null,
        gender: null,
        healthScore: null,
        riskLevel: null,
        suggestionForAdmission: null,
        nursingLevelName: null,
        admissionStatus: null,
        totalCheckDate: null,
        physicalExamInstitution: null,
        physicalReportUrl: null,
        assessmentTime: null,
        reportSummary: null,
        diseaseRisk: null,
        abnormalAnalysis: null,
        systemScore: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询健康评估列表 */
    getList() {
      this.loading = true;
      listAssessment(this.queryParams).then(response => {
        this.assessmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        elderName: null,
        idCard: null,
        birthDate: null,
        age: null,
        gender: null,
        healthScore: null,
        riskLevel: null,
        suggestionForAdmission: null,
        nursingLevelName: null,
        admissionStatus: null,
        totalCheckDate: null,
        physicalExamInstitution: null,
        physicalReportUrl: null,
        assessmentTime: null,
        reportSummary: null,
        diseaseRisk: null,
        abnormalAnalysis: null,
        systemScore: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加健康评估";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAssessment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改健康评估";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAssessment(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAssessment(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除健康评估编号为"' + ids + '"的数据项？').then(function() {
        return delAssessment(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('nursing/assessment/export', {
        ...this.queryParams
      }, `assessment_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
